Dim MinNemico As New Vector3()
Dim MaxNemico As New Vector3()
Me.BoundingBox(Nemico, MinNemico, MaxNemico)
Dim Colpito As Boolean = False
'equazione retta
'y + giocatore.pos.Z = coeff * x + giocatore.pos.X
'y + giocatore.pos.Z - coeff * x - giocatore.pos.X = 0
Dim coeff As Double = Math.Tan(90 - Rad(AngoloGiocatore))
Dim a1 As Double = -coeff
Dim b1 As Double = 1
Dim c1 As Double = -(Giocatore.pos.Z - Giocatore.pos.X)
'equazione diagonale rettangolo
'(y-y1)\(y2-y1)=(x-x1)\(x2-x1)
'(y - minnemico.z)\(maxnemico.z - minnemico.z) = (x - minnemico.x)\(maxnemico.x - minnemico.x)
Dim n1 As Double = MinNemico.Z
Dim n2 As Double = MaxNemico.Z - MinNemico.Z
Dim n3 As Double = MinNemico.X
Dim n4 As Double = MaxNemico.X - MinNemico.X
'(y - n1)\n2 = (x - n3)\n4
'n4(y-n1) = n2(x-n3)
'n4*y + n4*n1 = n2*x - n2*n3
'-n2*x + n4*y = n2*n3 - n4*n3
Dim a2 As Double = -n2
Dim b2 As Double = n4
Dim c2 As Double = n2 * n3 - n4 * n3
Dim p As PointF = Me.Cramer(a1, b1, c1, a2, b2, c2)
Dim rect As New RectangleF(MinNemico.X, MinNemico.Z, MaxNemico.X - MinNemico.X, MaxNemico.Z - MinNemico.Z)
If rect.Contains(p) Then
Nemici.RemoveAt(i)
Sparo.Play(0, BufferPlayFlags.Default)
If Nemici.Count = 0 Then
My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\Livello.txt", Livello + 1, False)
FineLivello.Play(0, BufferPlayFlags.Default)
TimerTempo.Stop()
Me.GeneraLivello()
End If
Exit For
End If